﻿#region Usings

using System.Text.RegularExpressions;
using System.Windows.Browser;

#endregion

namespace SilverBox.Helpers
{
    public class HtmlHelper
    {
        /// <summary>
        /// Remove HTML tags and empty newlines and spaces and leading spaces
        /// </summary>
        /// <param name="html">Html code to clear</param>
        /// <returns>Plain text</returns>
        public static string ClearHtml(string html)
        {
            // Remove HTML tags and empty newlines and spaces and leading spaces
            var formattedValue = Regex.Replace(html, "<.*?>", "");
            formattedValue = Regex.Replace(formattedValue, @"\n+\s+", "\n\n");
            formattedValue = formattedValue.TrimStart(' ');
            formattedValue = HttpUtility.HtmlDecode(formattedValue);

            //if(length > 0 && formattedValue.Length >= length)
            //    formattedValue = formattedValue.Substring(0, length - 1);

            return formattedValue;
        }
    }
}